package com.candy.control;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import java.io.File;
import java.io.IOException;

@Controller
public class FileUploadController {
    @RequestMapping("/upload.do")
    public ModelAndView upload(@RequestParam("img")MultipartFile file) throws IOException {

//        判断用户是否进行了图片上传操作
        if(file!=null){
//            执行图片上传操作，指定图片上传位置
            file.transferTo(new File("E:\\photo\\"+file.getOriginalFilename()));
        }
        ModelAndView mv=new ModelAndView();
        mv.setViewName("welcome");
        mv.addObject("msg",file.getOriginalFilename()+",上传成功！");
    return mv;
    }


}
